import { cloneDeep, } from 'lodash-es';

let jobLogList: JobLogRecord[] = [
  {
    "createBy": null,
    "createTime": "2024-07-14 00:40:17",
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "jobLogId": 6,
    "jobName": "系统默认（多参）",
    "jobGroup": "DEFAULT",
    "invokeTarget": "ryTask.ryMultipleParams('ry', true, 2000L, 316.50D, 100)",
    "jobMessage": "系统默认（多参） 总共耗时：0毫秒",
    "status": "0",
    "exceptionInfo": "",
    "startTime": null,
    "stopTime": null
  },
  {
    "createBy": null,
    "createTime": "2024-07-14 00:40:15",
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "jobLogId": 5,
    "jobName": "系统默认（有参）",
    "jobGroup": "DEFAULT",
    "invokeTarget": "ryTask.ryParams('ry')",
    "jobMessage": "系统默认（有参） 总共耗时：0毫秒",
    "status": "0",
    "exceptionInfo": "",
    "startTime": null,
    "stopTime": null
  },
  {
    "createBy": null,
    "createTime": "2024-07-14 00:40:13",
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "jobLogId": 4,
    "jobName": "系统默认（无参）",
    "jobGroup": "DEFAULT",
    "invokeTarget": "ryTask.ryNoParams",
    "jobMessage": "系统默认（无参） 总共耗时：0毫秒",
    "status": "0",
    "exceptionInfo": "",
    "startTime": null,
    "stopTime": null
  },
  {
    "createBy": null,
    "createTime": "2024-07-14 00:40:11",
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "jobLogId": 3,
    "jobName": "系统默认（多参）",
    "jobGroup": "DEFAULT",
    "invokeTarget": "ryTask.ryMultipleParams('ry', true, 2000L, 316.50D, 100)",
    "jobMessage": "系统默认（多参） 总共耗时：0毫秒",
    "status": "0",
    "exceptionInfo": "",
    "startTime": null,
    "stopTime": null
  },
  {
    "createBy": null,
    "createTime": "2024-07-14 00:40:08",
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "jobLogId": 2,
    "jobName": "系统默认（有参）",
    "jobGroup": "DEFAULT",
    "invokeTarget": "ryTask.ryParams('ry')",
    "jobMessage": "系统默认（有参） 总共耗时：0毫秒",
    "status": "0",
    "exceptionInfo": "",
    "startTime": null,
    "stopTime": null
  },
  {
    "createBy": null,
    "createTime": "2024-07-14 00:40:06",
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "jobLogId": 1,
    "jobName": "系统默认（无参）",
    "jobGroup": "DEFAULT",
    "invokeTarget": "ryTask.ryNoParams",
    "jobMessage": "系统默认（无参） 总共耗时：0毫秒",
    "status": "0",
    "exceptionInfo": "",
    "startTime": null,
    "stopTime": null
  }
];

const mocks: MockRecord[] = [
  {
    method: "get",
    url: "/api/monitor/jobLog/list",
    response(option) {
      const copyList = cloneDeep(jobLogList);

      let resList = jobLogList;

      if (option.query.pageNum) {
        resList = copyList.splice((option.query.pageNum - 1) * option.query.pageSize, option.query.pageSize);
      }

      const resData: responseType = {
        code: 200,
        msg: "查询成功",
        total: jobLogList.length,
        ...(option.query.pageNum ? { rows: resList } : { data: resList })
      }

      return resData;
    }
  },
  {
    method: "get",
    url: "/api/monitor/jobLog/:jobLogId",
    response(option) {
      const resJobLog = jobLogList.find(item => item.jobLogId == option.query.jobLogId);

      const resData: responseType = {
        code: resJobLog ? 200 : 500,
        msg: resJobLog ? "查询成功" : "查询失败",
        data: resJobLog,
      }

      return resData;
    }
  },
  {
    method: "post",
    url: "/api/monitor/jobLog",
    response(option) {
      const newJobLog = option.body;

      newJobLog.jobLogId = jobLogList.length + 1;
      jobLogList.unshift(newJobLog);

      const resData: responseType = {
        code: 200,
        msg: "新增成功",
      }

      return resData;
    }
  },
  {
    method: "put",
    url: "/api/monitor/jobLog",
    response(option) {
      const newJobLog = option.body;

      const index = jobLogList.findIndex(item => item.jobLogId == newJobLog.jobLogId);

      jobLogList.splice(index, 1, newJobLog);

      const resData: responseType = {
        code: 200,
        msg: "修改成功",
      }

      return resData;
    }
  },
  {
    method: "delete",
    url: "/api/monitor/jobLog/:jobLogIds",
    response(option) {
      const jobLogIds = option.query.jobLogIds.split(',');

      const filterList = jobLogList.filter(item => !jobLogIds.includes(String(item.jobLogId)));

      jobLogList = filterList;

      const resData: responseType = {
        code: 200,
        msg: "删除成功",
      }
      return resData;
    }
  }
];

export default mocks;